package cn.z2huo.knowledge.basic.datetime.newtime;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

/**
 * <p>
 *
 * @author z2huo
 */
public class InstantTest {

    public static void main(String[] args) {
        System.out.println(LocalDateTime.now());
        System.out.println(Instant.now());
        System.out.println();

        LocalDateTime dateTime = LocalDateTime.of(2025, 4, 1, 12, 0, 0);

        System.out.println(dateTime);
        System.out.println(dateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
        System.out.println();

        System.out.println(dateTime.atZone(ZoneId.of("Asia/Shanghai")).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
        System.out.println(dateTime.atZone(ZoneId.of("Asia/Shanghai")).toInstant());
        System.out.println(dateTime.atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli());
        System.out.println();

        System.out.println(Instant.ofEpochMilli(1743480000000L));
        System.out.println(Instant.ofEpochMilli(1743480000000L).atZone(ZoneId.of("Asia/Shanghai")));
        System.out.println(LocalDateTime.ofInstant(Instant.ofEpochMilli(1743480000000L), ZoneId.of("Asia/Shanghai")));
        System.out.println(LocalDateTime.ofInstant(Instant.ofEpochMilli(1743480000000L), ZoneId.of("Asia/Shanghai")).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
        System.out.println();

        Instant instant = dateTime.toInstant(ZoneOffset.of("+8"));
        System.out.println(instant);
        System.out.println(instant.atZone(ZoneId.of("Asia/Shanghai")));
        System.out.println(instant.atZone(ZoneId.of("Asia/Shanghai")).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
        System.out.println();

        Instant plusInstant = instant.plusSeconds(10);
        System.out.println(plusInstant);
        System.out.println(plusInstant.atZone(ZoneId.of("Asia/Shanghai")).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
        System.out.println();

        Instant nowInstant = Instant.now();
        System.out.println(nowInstant);
        System.out.println(nowInstant.atZone(ZoneId.of("Asia/Shanghai")).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
        System.out.println(nowInstant.plusSeconds(10).atZone(ZoneId.of("Asia/Shanghai")).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));

    }
}
